<template>
  <div class="nav">
    <div class="nav-item">
      <span class="text">签约状态</span>
      <el-select placeholder="请选择" v-model="agency.status" @change="statusChange">
        <el-option label="待审核" value="0" />
        <el-option label="待支付" value="1" />
        <el-option label="已驳回" value="2" />
        <el-option label="生效中" value="3" />
        <el-option label="已过期" value="4" />
      </el-select>
    </div>
    <div class="nav-item">
      <span class="text">签约机构</span>
      <el-select placeholder="请选择" v-model="agency.organId" @change="organIdChange">
        <el-option :label="item.name" :value="item.id" v-for="(item, index) in agencyOrgan" :key="index" />
      </el-select>
    </div>
    <div class="nav-item">
      <span class="text">医生团队</span>
      <el-select placeholder="请选择" v-model="agency.teamId" @change="serviceBasicChange">
        <el-option :label="item.name" :value="item.id" v-for="(item, index) in TeamList" :key="index" />
      </el-select>
    </div>
    <div style="position: absolute; right: 0">
      <el-button type="primary">导出</el-button>
      <el-button type="warning" @click="clear">重置</el-button>
    </div>
  </div>
  <div class="nav">
    <div class="nav-item">
      <span class="text">服务包</span>
      <el-select placeholder="请选择" v-model="agency.serviceId" @change="ServiceChange">
        <el-option :label="item.name" :value="item.id" v-for="(item, index) in ServiceBasicList" :key="index" />
      </el-select>
    </div>
    <div class="nav-item">
      <span class="text">居民标签</span>
      <el-select placeholder="请选择" v-model="agency.teamId" @change="serviceBasicChange">
        <el-option :label="item.label" :value="item.name" v-for="(item, index) in residentLabel" :key="index" />
      </el-select>
    </div>
    <!-- <div class="nav-item">
      <span class="text">选择日期</span>
      <el-date-picker
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        v-model="time"
        @change="timeChange"
      />
    </div> -->
    <div class="nav-item" style="margin-right: 0">
      <el-input style="width: 370px" class="w-50 m-2" placeholder="备注" suffix-icon="Search" v-model="agency.searchKey"
        @change="searchKeyChange" />
    </div>
    <!-- <div class="iconBox">
      <el-icon>
        <Fold />
      </el-icon>
      <el-icon>
        <Menu />
      </el-icon>
    </div> -->

  </div>
</template>

<script lang="ts" setup>
import { ref, watch } from "vue";
import api from "@/api";
import { agencyType } from "@/types/yzy/agency";
// import sj from "@/utils/yzy/sj";
//页数信息
const page = defineProps({
  page: Number,
  count: Number,
});
//给父组件传值

//分页器接收父组件的传值
let emit = defineEmits<{
  (e: "change1", val: any): void;
}>();
//时间
const time = ref();
//服务包
const serviceDis = ref(true);
//医生团队
const doctorDis = ref(true);
//签约参数
const agency = ref<agencyType>({
  status: null,
  organId: null,
  teamId: null,
  serviceId: null,
  startTime: null,
  endTime: null,
  searchKey: null,
  page: page.page as number,
  count: page.count as number,
});
//居民标签
const residentLabel = ref()
//监听器
watch(page, (New) => {
  agency.value.page = New.page as number;
  agency.value.count = New.count as number;
  getAgencyList();
});
console.log(agency.value);
//居民标签
const getResidentLabelData = async () => {
  const result = await api.residentAdmin.getResidentLabel()
  console.log('医生标签', result.data.data.result);
  residentLabel.value = result.data.data.result.map((item: any) => {
    return {
      label: item.name,
      value: item.id
    }
  })
  console.log("7777778888888", residentLabel.value);


}
// //签约列表
// const agencyList = ref([
//   {
//     id: "88579930-ee50-11ed-8059-0ba99686sd93",
//     number: "20235121407123",
//     rname: "白素",
//     IDCard: "512382188902120867",
//     tel: "13366668888",
//     status: 3,
//     tname: "段宏团队",
//     dname: "段宏",
//     sname: "老人服务包",
//     takingEffectTime: "2023-05-17 00:00:00",
//     period: 1,
//   },
//   {
//     id: "67e98bc0-ee1b-11ed-8459-c76f227cdls2",
//     number: "20235121408192",
//     rname: "小青",
//     IDCard: "513777188109182673",
//     tel: "18899991111",
//     status: 3,
//     tname: "段宏团队",
//     dname: "段宏",
//     sname: "老人服务包",
//     takingEffectTime: "2023-05-13 00:00:00",
//     period: 1,
//   },
// ]);
//机构列表
const agencyOrgan = ref([
  {
    address: "四川省成都市武侯区致民东路8号",
    contactName: "李瑞",
    contactTel: "(028)85434379",
    description:
      "成都市武侯区望江路社区卫生服务中心是政府举办的公益性医疗机构。中心系四川省全科医学中心社区培训基地、华西医院全科医学基层实践基地，同时还是四川大学华西医院、四川省人民医院、成都市第二人民医院等医院的对口辅导和双向转诊单位。2018年被国家卫生计生委评为“全国优质服务示范社区卫生服务中心”。",
    flag: 0,
    id: "67e98bc0-ee1b-11ed-8459-c76f227ca777",
    name: "成都市武侯区望江路社区卫生服务中心",
    number: "2023591753249",
    picture: "",
  },
]);
//团队列表
const TeamList = ref([
  {
    id: "88579930-ee50-11ed-8059-0ba99686esd1",
    number: "202359172987",
    name: "陈晓平团队",
    picture: "public/upload/u5598.png",
    organId: "67e98bc0-ee1b-11ed-8459-c76f227ca578",
    score: 5,
    shareCount: 0,
    status: 0,
    flag: 0,
  },
]);
//服务包列表
const ServiceBasicList = ref([
  {
    id: "7909bde0-828b-11ed-a736-b1a95d18c716",
    name: "0~6岁儿童服务包",
    targetAudience: "0~6岁儿童",
    picture: "public/upload/u4827.png",
    labelArr: [
      {
        name: "儿童",
      },
    ],
  },
]);
//签约状态更改
const statusChange = () => {
  getAgencyList();
};
//签约机构更改
const organIdChange = () => {
  getAgencyList();
  getTeamByOrganId(); //团队
  doctorDis.value = false;
  agency.value.serviceId = null;
  agency.value.teamId = null;
};
//医生团体更改
const serviceBasicChange = () => {
  getAgencyList();
  getServiceBasic();
  serviceDis.value = false;
  agency.value.serviceId = null;
};
//服务包更改
const ServiceChange = () => {
  getAgencyList();
};
//时间更改
// const timeChange = () => {
//   agency.value.startTime = sj(time.value[0]);
//   agency.value.endTime = sj(time.value[1]);
//   getAgencyList();
// };
//关键字更改
const searchKeyChange = () => {
  getAgencyList();
};
//重置
const clear = () => {
  doctorDis.value = true;
  serviceDis.value = true;
  agency.value.status = null;
  agency.value.organId = null;
  agency.value.teamId = null;
  agency.value.serviceId = null;
  agency.value.startTime = null;
  agency.value.endTime = null;
  time.value = null;
  agency.value.searchKey = null;
  getAgencyList(); //列表
};
//获取签约列表
const getAgencyList = async () => {
  let result = await api.Agency.getAgencyApi(agency.value);
  if (result.data.code === 200) {
    emit("change1", {
      data: result.data.data.result,
      total: result.data.data.total,
    });
  }
};
//获取所有机构
const getAllChcsOrgan = async () => {
  let result = await api.Agency.getAllChcsOrganApi();
  agencyOrgan.value = result.data.data.rows;
  // console.log(agencyOrgan.value);
};
//根据机构获取团队
const getTeamByOrganId = async () => {
  let result = await api.Agency.getTeamByOrganId(
    agency.value.organId as string
  );
  TeamList.value = result.data.data;
};
//根据团队获取服务包
const getServiceBasic = async () => {
  console.log(agency.value.teamId);
  let result = await api.Agency.getServiceBasicApi(
    agency.value.teamId as string
  );
  ServiceBasicList.value = result.data.data;
};
getAgencyList(); //列表
getAllChcsOrgan(); //机构
getResidentLabelData()//医生标签
</script>
<style lang="scss">
.header {
  @include flex(none, center, none);

  .line {
    width: 6px;
    height: 20px;
    background-color: skyblue;
    border-radius: 5px;
    margin-right: 10px;
  }
}

.nav {
  position: relative;
  margin-top: 25px;
  @include flex(none, center, none);

  .text {
    display: inline-block;
    width: 55px;
    font-size: 13px;
    color: #999;
    text-align: right;
    margin-right: 15px;
  }

  .nav-item {
    margin-right: 20px;

    .el-date-editor {
      width: 360px;
    }
  }

  // .iconBox {
  //   margin-left: 220px;

  //   .el-icon {
  //     color: #999;
  //     margin-right: 10px;
  //   }

  //   .el-icon:hover {
  //     cursor: pointer;
  //     color: #1877f2;
  //   }
  // }

  .el-input__wrapper {
    box-sizing: border-box;
    width: 200px;
    height: 40px;
  }

  .el-button {
    height: 40px;
    color: white;
  }
}

.el-pagination {
  justify-content: end;
  margin: 20px 0;
}
</style>
